import {getRect} from './getRect'
/**
 * @desc 用于页面中滚动时固定某个控件
 * @pageInstance
 * @fixedDataKey 标识是否是固定状态的data
 * @offsetTop {number} 固定后距离顶部距离
 */
export const scrollFixed = (pageInstance, fixedDataKey, offsetTop = 0, selector = '.fixed-top-wrap') => {
  let _page = pageInstance
  getRect(selector, ({top}) => {
    if (top < offsetTop) {
      _page.setData({
        [fixedDataKey]: true
      })
    } else {
      _page.setData({
        [fixedDataKey]: false
      })
    }
  })
}